package top.littleze.aiattendance.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.littleze.aiattendance.entity.*;
import top.littleze.aiattendance.service.TeacherService;
import top.littleze.aiattendance.utils.page.PageResult;
import top.littleze.aiattendance.utils.page.Reply;

import java.util.List;

/**
 * @Author ZhaoGengze
 * @Date 2021/7/9 11:36
 */

@RestController
@ResponseBody
@RequestMapping("/teacher")
@Slf4j
public class TeacherController {

    @Autowired
    TeacherService teacherService;


    /**
     * 授课列表查询
     * @param teacherId
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/course")
    public Reply<List<AttendanceCourseEntity>> getTeacherCourse(@RequestParam("teacherId") String teacherId,
                                                            @RequestParam("page") int page, @RequestParam("limit") int limit) {
        log.info("教师课表查询：teacherId: {}, page: {}, limit: {}", teacherId, page, limit);
        return teacherService.queryTeacherCourse(teacherId, page, limit);
    }

    /**
     * 根据课程查询学生
     * @param courseId
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/student")
    public Reply<List<AttendanceStudentEntity>> getStudentList(@RequestParam("courseId") String courseId,
                                                               @RequestParam("page") int page, @RequestParam("limit") int limit) {
        log.info("学生列表查询：courseId: {}, page: {}, limit: {}", courseId, page, limit);
        return teacherService.queryStudentList(courseId, page, limit);
    }

    /**
     * 根据教师id查询所有课程学生名单
     */
    @RequestMapping("/course-student")
    public Reply<List<AttendanceSCEntity>> getCourseStudentList(@RequestParam("teacherId") String teacherId,
                                                                @RequestParam("page") int page, @RequestParam("limit") int limit) {
        log.info("根据教师ID查询课程学生：courseId: {}, page: {}, limit: {}", teacherId, page, limit);
        return teacherService.queryCourseStudentList(teacherId, page, limit);
    }


    /**
     * 删除课程
     * @param courseId
     * @return
     */
    @RequestMapping("/deleteCourse")
    public Reply<Void> deleteCourse(@RequestParam("courseId") String courseId) {
        log.info("删除课程入参： 课程id: {}", courseId);
        return teacherService.deleteCourse(courseId);
    }

    /**
     * 根据ID修改课程信息
     * @param courseEntity
     * @return
     */
    @RequestMapping("/updateCourse")
    public Reply<Void> updateCourse(@RequestBody AttendanceCourseEntity courseEntity) {
        log.info("修改课程信息入参：{}", courseEntity);
        // 前端需要传id
        return teacherService.updateCourse(courseEntity);
    }

    /**
     * 新建课程
     * @param courseEntity
     * @return
     */
    @RequestMapping("insertCourse")
    public Reply<Void> insertCourse(@RequestBody AttendanceCourseEntity courseEntity) {
        log.info("新增课程信息入参：{}", courseEntity);
        return teacherService.insertCourse(courseEntity);
    }

    /**
     * 出勤查询
     * @param courseId
     * @return
     */
    @RequestMapping("queryAttendance")
    public Reply<List<AttendanceLogEntity>> queryAttendance(@RequestParam("courseId") String courseId) {
        log.info("出勤查询入参：课程ID：{}", courseId);
        return teacherService.queryAttendance(courseId);
    }

}


